package 随机点名多方面介绍;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class 概率性随机点名 {
    public static void main(String[] args) {
        /*
        班级有N个学生，
        要求：
        70%随机到男生
        30%随机到女生
         */
        //定义男生
        ArrayList<String> schoolBoy=new ArrayList<>();
        //定义女生
        ArrayList<String> schoolGirl=new ArrayList<>();

        //添加男生名字
        Collections.addAll(schoolBoy,"马超","张飞","刘备","关羽","张机","曹操","孙权");
        //定义女生名字
        Collections.addAll(schoolGirl,"蔡文姬","妲己","甄洛","貂蝉","孙尚香");

        //定义概率集合
        ArrayList<Integer>list=new ArrayList<>();
        //设置概率
        Collections.addAll(list,1,1,1,1,1,1,1);
        Collections.addAll(list,0,0,0);
        //打乱概率集合
        Collections.shuffle(list);
        Random r=new Random();
        //获取男女
        int index=r.nextInt(list.size());
        int number=list.get(index);
        System.out.println(number);

        //1：代表男生
        //0.代表女生
        if(number==1){
            //获取随机数
            Random boy=new Random();
            int indexBoy=boy.nextInt(schoolBoy.size());
            //获取索引的名字
            String numberBoy=schoolBoy.get(indexBoy);
            //将名字打印出来
            System.out.println(numberBoy);
        }else if(number==0){
            Random girl=new Random();
            int indexGilr=girl.nextInt(schoolGirl.size());
            String numberGilr=schoolGirl.get(indexGilr);
            System.out.println(numberGilr);
        }else{
            System.out.println("数据错误!");
        }
    }
}
